package dfl.bysj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dfl.bysj.entity.Academy;
import dfl.bysj.entity.Grade;
import dfl.bysj.entity.Student;
import dfl.bysj.entity.UserTeacherStudent;
import dfl.bysj.entity.VO.StudentVO;
import dfl.bysj.mapper.UserTeacherStudentMapper;
import dfl.bysj.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DFL
 * @since 2022-04-26
 */
@Service
public class UserTeacherStudentServiceImpl extends ServiceImpl<UserTeacherStudentMapper, UserTeacherStudent> implements UserTeacherStudentService {

    private StudentService studentService;

    private GradeService gradeService;

    private AcademyService academyService;

    @Autowired
    public void setAcademyService(AcademyService academyService) {
        this.academyService = academyService;
    }

    @Autowired
    public void setGradeService(GradeService gradeService) {
        this.gradeService = gradeService;
    }

    @Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }

    @Override
    public StudentVO getStudentVO(String stuUseId) {
       UserTeacherStudent userTeacherStudent= getOne(
                new QueryWrapper<UserTeacherStudent>()
                        .eq("stu_use_id", stuUseId)
        );

       //通过stuid获取学生信息
       Student student =studentService.getStudentById(userTeacherStudent.getStuId());

       //获取班级、学院
       Grade grade= gradeService.getGradeById(student.getGraId());

        Academy academy=academyService.getAcademyById(grade.getAcaId());

       return makeStudentVO(student,grade,academy);

    }

    private StudentVO makeStudentVO(Student student, Grade grade, Academy academy) {
        StudentVO studentVO=new StudentVO();
        studentVO.setStuId(Long.valueOf(student.getStuId()));
        studentVO.setStuName(student.getStuName());
        studentVO.setStuPhone(Long.valueOf(student.getStuPhone()));
        studentVO.setGrade(grade.getGraName());
        studentVO.setAcademy(academy.getAcaName());
        return studentVO;
    }
}
